package ch.rheintalconnection.sysventory.presentation.panels;

import java.util.List;

import ch.rheintalconnection.sysventory.domain.Client;
import ch.rheintalconnection.sysventory.domain.ScanEntry;
import ch.rheintalconnection.sysventory.technicalServices.IDataReader;

import com.vaadin.data.Item;
import com.vaadin.ui.Table;
import com.vaadin.ui.VerticalLayout;

public class StatisticComputerPanel extends VerticalLayout{

	private static final long serialVersionUID = 6338433672383813165L;


	public StatisticComputerPanel(IDataReader dataReader){
		Table table = new Table();
		table.setSizeFull();
		this.addComponent(table);
		
		List<Client> clients = dataReader.selectAllClients();
		
		table.addContainerProperty("ID", String.class, null);
		table.addContainerProperty("MAC-Adresse", String.class, null);
		table.addContainerProperty("Computer-Name", String.class, null);
		table.addContainerProperty("IP-Adresse", String.class, null);
		
		for (Client client : clients) {
			
			Object newItemId = table.addItem();
			Item row = table.getItem(newItemId);
			
			ScanEntry scanEntry = dataReader.selectNewestScanEntry(client);
			
			row.getItemProperty("ID").setValue(client.getId());
			row.getItemProperty("MAC-Adresse").setValue(client.getMacAddress());
			row.getItemProperty("Computer-Name").setValue(scanEntry.getComputer().getComputerName());
			row.getItemProperty("IP-Adresse").setValue(scanEntry.getNic().getIpAddress());
		}
	}
}
